package o;

import android.text.TextUtils;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;

public class cwi extends AsyLoader {
    private long ʼ = 0;
    private int ᐝ = 0;

    static class a {
        private static boolean ˏ(int i) {
            return i == 1021 || i == 1011;
        }

        public static boolean ˋ(int i) {
            if (ˏ(i)) {
                return ˎ(ccz.ॱ(), null);
            }
            return true;
        }

        public static String ˏ(int i, ResponseBean responseBean, boolean z) {
            BaseRequest ˎ = cvv.ˎ();
            ˎ.ˏ(1);
            ˎ.setRequestType(o.cvu.RequestStrategy.REQUEST_NETWORK_REF_CACHE);
            ˎ.setServiceType_(i);
            ˎ.setBlockIfProtocolNotAgreed(z);
            cwi o_cwi = new cwi(ˎ, null);
            ˎ.setUrl(cvx.ˎ(ˎ.targetServer));
            ResponseBean ˏ = o_cwi.ॱ();
            if (!(ˏ instanceof StartupResponse) || ˏ.getRtnCode_() != 0 || ˏ.getResponseCode() != 0) {
                return null;
            }
            ((StartupResponse) ˏ).ˎ(ˎ);
            if (responseBean == null || ((StartupResponse) ˏ).ˊ() == 1) {
                return ((StartupResponse) ˏ).ॱˊ();
            }
            responseBean.setResponseCode(ResponseBean.SERVICE_ZONE_NOT_SUPPORT_ERROR);
            return null;
        }

        public static boolean ˎ(int i, ResponseBean responseBean) {
            return ˏ(i, responseBean, true) != null;
        }
    }

    public cwi(BaseRequest o_cvu, IServerCallBack iServerCallBack) {
        super(o_cvu, iServerCallBack);
    }

    public static boolean ˏ(int i) {
        return a.ˋ(i);
    }

    protected String ʼ() {
        String ˎ = epb.ˎ();
        if (TextUtils.isEmpty(ˎ)) {
            return super.ʼ();
        }
        return ˎ;
    }

    public void ˋ(String str, String str2, ResponseBean responseBean) {
    }

    private void ˎ(String str) {
        if (ˎ() instanceof cvt) {
            cvt o_cvt = (cvt) ˎ();
            if (o_cvt.isNeedSign()) {
                cvp.ˎ.ˋ("ServerTaskEx", "resetSign，sign: " + str);
                o_cvt.setSign(str);
            }
        }
    }

    protected boolean ˎ(ResponseBean responseBean) {
        if (!(ˎ() instanceof cvt)) {
            return false;
        }
        boolean z;
        cvt o_cvt = (cvt) ˎ();
        o.cvx.a ˏ = cvx.ˏ(o_cvt.targetServer);
        if (ˏ.ˏ()) {
            Object ॱ = ˏ.ॱ();
            if (!(TextUtils.isEmpty(ॱ) || ॱ.equals(o_cvt.getUrl()))) {
                z = true;
            }
            z = false;
        } else {
            if (responseBean.getErrCause() == e.IO_EXCEPTION || responseBean.getErrCause() == e.CONNECT_EXCEPTION || responseBean.getErrCause() == e.UNKNOWN_EXCEPTION) {
                dnm.ˎ().ॱ(o_cvt.getUrl());
                z = false;
            }
            z = false;
        }
        if (z) {
            cvp.ˎ.ˋ("ServerTaskEx", "onRetryCompleted, trans to backupUrl");
            o_cvt.setUrl(ˏ.ॱ());
            this.ˎ = 0;
        }
        cvp.ˎ.ˋ("ServerTaskEx", "[" + o_cvt.getMethod_() + "]onRetryCompleted retry=" + z);
        return z;
    }

    public void ˋ() {
        this.ʼ = System.currentTimeMillis();
    }

    protected ResponseBean ˏ(BaseRequest o_cvu) {
        ResponseBean responseBean = null;
        if (ͺ()) {
            int ॱ = ccz.ॱ();
            if (o_cvu instanceof cvt) {
                ॱ = ((cvt) o_cvu).getServiceType_();
            }
            BaseRequest ˎ = cvv.ˎ();
            ˎ.ˏ(1);
            ˎ.setRequestType(o.cvu.RequestStrategy.REQUEST_NETWORK_REF_CACHE);
            ˎ.setServiceType_(ॱ);
            cwi o_cwi = new cwi(ˎ, null);
            ˎ.setUrl(cvx.ˎ(ˎ.targetServer));
            do {
                responseBean = o_cwi.ॱ();
                if ((responseBean instanceof StartupResponse) && responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                    ((StartupResponse) responseBean).ˎ(ˎ);
                    ˎ(((StartupResponse) responseBean).ॱˊ());
                }
            } while (o_cwi.ˏ(responseBean));
        }
        return responseBean;
    }

    private boolean ͺ() {
        if (!(ˎ() instanceof cvt)) {
            return false;
        }
        if (ˎ() instanceof cvv) {
            return false;
        }
        if (((cvt) ˎ()).isNeedSign()) {
            cvt o_cvt = (cvt) ˎ();
            if (o_cvt.getSign_() != null && o_cvt.getSign_().trim().length() == 0) {
                return true;
            }
        }
        return false;
    }

    public void ˋ(ResponseBean responseBean) {
        cwe.ˊ(responseBean, ˎ());
        if (this.ʼ > 0) {
            esr.ˊ(BaseRequest.getMethod_(ˎ()), System.currentTimeMillis() - this.ʼ);
        }
        cvt o_cvt = (cvt) ˎ();
        if (o_cvt.isNeedRecallFront() && a.ˏ(responseBean.getRtnCode_())) {
            int i = this.ᐝ;
            this.ᐝ = i + 1;
            if (i < 3) {
                cvp.ˎ.ˊ("ServerTaskEx", "reCallFrontSync, hcrID or sign error! method:" + ˎ().getMethod_() + ", rtnCode:" + responseBean.getRtnCode_());
                String ˏ = a.ˏ(o_cvt.getServiceType_(), responseBean, o_cvt.isBlockIfProtocolNotAgreed());
                if (ˏ != null) {
                    ˎ(ˏ);
                    responseBean.setResponseCode(1);
                }
            }
        }
    }

    public AsyLoader ʻ() {
        AsyLoader o_cwi = new cwi(ˎ(), this.ˊ);
        o_cwi.ʽ(ॱॱ());
        o_cwi.ॱ = this.ॱ;
        o_cwi.ˋ = this.ˋ;
        o_cwi.ॱ(ˊॱ());
        if (o_cwi.ˎ() instanceof cvt) {
            cvt o_cvt = (cvt) o_cwi.ˎ();
            o_cvt.setSign(HcridSession.ˋ().ˏ(o_cvt.getServiceType_()));
        }
        return o_cwi;
    }
}
